package com.l.web.master.index;

import com.l.web.WebConstant;
import com.l.web.master.system.config.Config;
import com.l.web.master.system.config.ConfigService;
import com.l.web.master.system.menu.MenuService;
import com.l.web.master.system.user.User;
import com.l.web.util.ContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping(WebConstant.MASTER_URI)
public class IndexController {

    @Autowired
    private ConfigService configService;

    @Autowired
    private MenuService menuService;

    @RequestMapping("/index")
    //@Privilege(module = "公共",function = "首页" ,operation = "查看")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        User user = ContextUtil.getLoginUser();
        List menus = menuService.menu(user);
        modelMap.put("menus", menus);

        Config global = configService.getConfig(WebConstant.CONFIG_KEY_GLOBAL);
        modelMap.put("global", global);

        return new ModelAndView(WebConstant.MASTER_URI + "/index");
    }

    @RequestMapping("childrenMenu")
    public ModelAndView childrenMenu(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        String parentId = request.getParameter("parentid");
//        List<Cluster> menus = indexService.getChildrenMenu(parentId);
//        modelMap.put("menu1", menus);
        return new ModelAndView(WebConstant.MASTER_URI + "/childrenMenu");
    }
}
